package com.ls.aicoderbackend.core.parser;

import cn.hutool.core.util.ObjUtil;
import com.ls.aicoderbackend.exception.BusinessException;
import com.ls.aicoderbackend.exception.ErrorCode;
import com.ls.aicoderbackend.exception.ThrowUtils;
import com.ls.aicoderbackend.model.enums.CodeGenTypeEnum;

public class CodeParserExecutor {

    private static final HtmlCodeParser htmlCodeParser = new HtmlCodeParser();
    private static final MultiFileCodeParser multiFileCodeParser = new MultiFileCodeParser();

    public static Object executeParser(String codeContent, CodeGenTypeEnum codeGenTypeEnum) {
        ThrowUtils.throwIf(ObjUtil.isNull(codeContent), ErrorCode.PARAMS_ERROR, "模式类型为空");
        return switch (codeGenTypeEnum) {
            case HTML -> htmlCodeParser.parserCode(codeContent);
            case MULTI_FILE -> multiFileCodeParser.parserCode(codeContent);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR, "不支持的代码生成类型：" + codeGenTypeEnum.getText());
        };
    }
}
